HTMLElement: focus() method |
您所在的位置:网站首页 › force button › HTMLElement: focus() method |
This example demonstrates how you can set the focus on a button element. HTMLFirst we define three buttons. Both the middle and right button will set focus on the left-most button. The right right-most button will also specify focusVisible. htmlButton Click to set focus on "Button" Click to set focus and focusVisible on "Button" JavaScriptThe code below sets up handlers for click events on the middle and right buttons. jsdocument.getElementById("focusButton").addEventListener("click", () => { document.getElementById("myButton").focus(); }); document .getElementById("focusButtonVisibleIndication") .addEventListener("click", () => { document.getElementById("myButton").focus({ focusVisible: true }); }); ResultSelect either the middle button or right-most button to set focus on the left-most button. Browsers do not usually show visible focus indication on button elements when focus is set programmatically, so the effect of selecting the middle button may not be obvious. However provided the focusVisible option is supported on your browser, you should see focus changing on the left-most button when the right-most button is selected. |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |